package com.yun.platform.config;


import com.yun.platform.config.interceptor.JWTInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 *  laich
 *  MVC 所有URI 统一拦截
 *
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //参数为我们自定义类，实现了HandlerInterceptor接口重写了三个方法

        registry.addInterceptor(new JWTInterceptor())
                .addPathPatterns("/**")   //拦截所有的路径
                .excludePathPatterns("/swagger-ui.html")//放行
                .excludePathPatterns("/iot/**") // 测试放行 两个* 号
                .excludePathPatterns("/api-docs")
                .excludePathPatterns("/error")
                .excludePathPatterns("/webjars/**")
                .excludePathPatterns("/swagger**/**")
                .excludePathPatterns("/configuration/security")
                .excludePathPatterns("/nologin/**","/doc.html"); //放行

    }

    /**
     * 解决跨域
     * @param registry
     */
    /*@Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("GET", "POST", "DELETE", "PUT")
                .maxAge(3600);
    }*/


}